//
//  CreateVoteViewController.m
//  CLUBiN - DJ
//
//  Created by Dominic Gatzen on 13.01.12.
//  Copyright (c) 2012 private. All rights reserved.
//

#import "CreateVoteViewController.h"


@implementation CreateVoteViewController
@synthesize submitButton;

@synthesize artist1, artist2, artist3, title1, title2, title3;
@synthesize icon1, icon2, icon3;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (IBAction)submit:(id)sender{
    
}
- (IBAction)selectTrack:(id)sender {
    MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes:(MPMediaTypeMusic |MPMediaTypePodcast)];
    picker.allowsPickingMultipleItems = YES;
    picker.delegate = self;
    [self presentModalViewController:picker animated:YES];
    [picker release]; 
}
#pragma mark MediaItemPicker delegate methods
- (void)mediaPicker:(MPMediaPickerController *)mediaPicker
    didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
    // Remove the picker
    [self dismissModalViewControllerAnimated:YES]; 
    
    switch (mediaItemCollection.count) {
        case 3:
            artist3.text = [[[mediaItemCollection items ] objectAtIndex:2] valueForProperty:MPMediaItemPropertyArtist];
            title3.text  = [[[mediaItemCollection items ] objectAtIndex:2] valueForProperty:MPMediaItemPropertyTitle];
            UIImage *im3 = [[[[mediaItemCollection items ] objectAtIndex:2] valueForProperty:MPMediaItemPropertyArtwork] imageWithSize:CGSizeMake(70, 70)];
            if (im3 != nil){
                icon3.image  = im3;
            }
            else{
                icon3.image = [UIImage imageNamed:@"icon72.png"];
            }
            [im3 release];
        case 2:
            artist2.text = [[[mediaItemCollection items ] objectAtIndex:1] valueForProperty:MPMediaItemPropertyArtist];
            title2.text  = [[[mediaItemCollection items ] objectAtIndex:1] valueForProperty:MPMediaItemPropertyTitle];
            UIImage *im2 = [[[[mediaItemCollection items ] objectAtIndex:1] valueForProperty:MPMediaItemPropertyArtwork] imageWithSize:CGSizeMake(70, 70)];
            if (im2 != nil){
                icon2.image  = im2;
            }
            else{
                icon2.image = [UIImage imageNamed:@"icon72.png"];
            }
            [im2 release];

        case 1:
            artist1.text = [[[mediaItemCollection items ] objectAtIndex:0] valueForProperty:MPMediaItemPropertyArtist];
            title1.text  = [[[mediaItemCollection items ] objectAtIndex:0] valueForProperty:MPMediaItemPropertyTitle];
            UIImage *im1 = [[[[mediaItemCollection items ] objectAtIndex:0] valueForProperty:MPMediaItemPropertyArtwork] imageWithSize:CGSizeMake(70, 70)];
            if (im1 != nil){
                icon1.image  = im1;
            }
            else{
                icon1.image = [UIImage imageNamed:@"icon72.png"];
            }
            [im1 release];
            break;
            
            
        default:
            break;
    }
    
}
-(void) mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker{
    [self dismissModalViewControllerAnimated:YES]; 
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
}
*/

- (void)viewDidUnload
{
    [self setSubmitButton:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)dealloc {
    [submitButton release];
    [super dealloc];
}
@end
